package com.yellowpage.bigdata.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.bigdata.data.NspOnofflogImeiDaySum;
import com.yellowpage.bigdata.service.NspOnofflogImeiDaySumService;

public class NspOnofflogImeiDaySumAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<NspOnofflogImeiDaySum> nspOnofflogImeiDaySumList = new ArrayList<NspOnofflogImeiDaySum>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private NspOnofflogImeiDaySum nspOnofflogImeiDaySum;
	private NspOnofflogImeiDaySumService nspOnofflogImeiDaySumService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_logDate;
		private String query_appVersion;
		private String query_operator;
		private String query_channelNo;
		private String query_createUser;
		private String query_createTime;
		private String query_note;
		private String query_onofflogImeiDaySumId;
		private String query_imeiDayCount;
		private String query_imeiAllCount;
		private String query_imeiNewCount;
		private String query_logDate_end;
		
	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspOnofflogImeiDaySum = nspOnofflogImeiDaySumService.getNspOnofflogImeiDaySum(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("logDate", query_logDate);
			    queryMap.put("query_logDate_end", query_logDate_end);
				queryMap.put("query_appVersion", query_appVersion);
				queryMap.put("query_operator", query_operator);
				queryMap.put("query_channelNo", query_channelNo);
	    	    	
		resultList = nspOnofflogImeiDaySumService.queryNspOnofflogImeiDaySumByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		nspOnofflogImeiDaySumService.saveNspOnofflogImeiDaySum(nspOnofflogImeiDaySum);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    if (nspOnofflogImeiDaySum.getLogDate().length() == 0) {
			this.addActionError("** LogDate 不能为空 !");
		}
			    	    	    if (nspOnofflogImeiDaySum.getAppVersion().length() == 0) {
			this.addActionError("** AppVersion 不能为空 !");
		}
			    	    	    if (nspOnofflogImeiDaySum.getOperator().length() == 0) {
			this.addActionError("** Operator 不能为空 !");
		}
			    	    	    if (nspOnofflogImeiDaySum.getChannelNo().length() == 0) {
			this.addActionError("** ChannelNo 不能为空 !");
		}
			    	    	    	    	    	    	    if (nspOnofflogImeiDaySum.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    	    	    	    	    	    	    	    	    	    
		this.setValidatorResult("/bigdata/NspOnofflogImeiDaySumAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    nspOnofflogImeiDaySum = nspOnofflogImeiDaySumService.getNspOnofflogImeiDaySum(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    nspOnofflogImeiDaySumService.updateNspOnofflogImeiDaySum(nspOnofflogImeiDaySum);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    if (nspOnofflogImeiDaySum.getLogDate().length() == 0) {
			this.addActionError("** LogDate 不能为空 !");
		}
			    			    if (nspOnofflogImeiDaySum.getAppVersion().length() == 0) {
			this.addActionError("** AppVersion 不能为空 !");
		}
			    			    if (nspOnofflogImeiDaySum.getOperator().length() == 0) {
			this.addActionError("** Operator 不能为空 !");
		}
			    			    if (nspOnofflogImeiDaySum.getChannelNo().length() == 0) {
			this.addActionError("** ChannelNo 不能为空 !");
		}
			    			    			    			    if (nspOnofflogImeiDaySum.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    			    			    			    			    		this.setValidatorResult("/bigdata/NspOnofflogImeiDaySumUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.nspOnofflogImeiDaySumService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲突删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setNspOnofflogImeiDaySum(NspOnofflogImeiDaySum nspOnofflogImeiDaySum) {
		this.nspOnofflogImeiDaySum = nspOnofflogImeiDaySum;
	}
	
	public NspOnofflogImeiDaySum getNspOnofflogImeiDaySum() {
		return nspOnofflogImeiDaySum;
	}
	 
	 
	 public void setNspOnofflogImeiDaySumService(NspOnofflogImeiDaySumService nspOnofflogImeiDaySumService) {
		this.nspOnofflogImeiDaySumService = nspOnofflogImeiDaySumService;
	}
	
	public List<NspOnofflogImeiDaySum> getNspOnofflogImeiDaySumList() {
		return nspOnofflogImeiDaySumList;
	}

	public void setNspOnofflogImeiDaySumList(List<NspOnofflogImeiDaySum> nspOnofflogImeiDaySumList) {
		this.nspOnofflogImeiDaySumList = nspOnofflogImeiDaySumList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_logDate() {
        return this.query_logDate;
    }
    
    public void setQuery_logDate(String logDate){
        this.query_logDate = logDate;
    }    

        public String getQuery_appVersion() {
        return this.query_appVersion;
    }
    
    public void setQuery_appVersion(String appVersion){
        this.query_appVersion = appVersion;
    }    

        public String getQuery_operator() {
        return this.query_operator;
    }
    
    public void setQuery_operator(String operator){
        this.query_operator = operator;
    }    

        public String getQuery_channelNo() {
        return this.query_channelNo;
    }
    
    public void setQuery_channelNo(String channelNo){
        this.query_channelNo = channelNo;
    }    

        public String getQuery_createUser() {
        return this.query_createUser;
    }
    
    public void setQuery_createUser(String createUser){
        this.query_createUser = createUser;
    }    

        public String getQuery_createTime() {
        return this.query_createTime;
    }
    
    public void setQuery_createTime(String createTime){
        this.query_createTime = createTime;
    }    

        public String getQuery_note() {
        return this.query_note;
    }
    
    public void setQuery_note(String note){
        this.query_note = note;
    }    

        public String getQuery_onofflogImeiDaySumId() {
        return this.query_onofflogImeiDaySumId;
    }
    
    public void setQuery_onofflogImeiDaySumId(String onofflogImeiDaySumId){
        this.query_onofflogImeiDaySumId = onofflogImeiDaySumId;
    }    

        public String getQuery_imeiDayCount() {
        return this.query_imeiDayCount;
    }
    
    public void setQuery_imeiDayCount(String imeiDayCount){
        this.query_imeiDayCount = imeiDayCount;
    }    

        public String getQuery_imeiAllCount() {
        return this.query_imeiAllCount;
    }
    
    public void setQuery_imeiAllCount(String imeiAllCount){
        this.query_imeiAllCount = imeiAllCount;
    }    

        public String getQuery_imeiNewCount() {
        return this.query_imeiNewCount;
    }
    
    public void setQuery_imeiNewCount(String imeiNewCount){
        this.query_imeiNewCount = imeiNewCount;
    }

	public String getQuery_logDate_end() {
		return query_logDate_end;
	}

	public void setQuery_logDate_end(String query_logDate_end) {
		this.query_logDate_end = query_logDate_end;
	}    

    
	
}
